#include "playbackplaybuttongroup.h"
#include <QHBoxLayout>

PlaybackPlayButtonGroup::PlaybackPlayButtonGroup(QWidget *parent)
    : QWidget(parent)
{
    setWindowFlags(Qt::FramelessWindowHint);
    setAttribute(Qt::WA_StyledBackground);  // 禁止父窗口样式影响子控件样式

    StopButton = new QPushButton(this);
    StopButton->setText("");
    StopButton->setFixedSize(32, 32);
    StopButton->setStyleSheet("QPushButton{background-image:url(:/playCtrlBar/resources/playctrlBar/stop.svg);border:none;}"
        "QPushButton:hover{background-image:url(:/playCtrlBar/resources/playctrlBar/stop_hover.svg);border:none;}"
        "QPushButton:pressed{background-image:url(:/playCtrlBar/resources/playctrlBar/stop.svg);border:none;}");

    PreButton = new QPushButton(this);
    PreButton->setText("");
    PreButton->setFixedSize(32, 32);
    PreButton->setStyleSheet("QPushButton{background-image:url(:/playCtrlBar/resources/playctrlBar/pre.svg);border:none;}"
        "QPushButton:hover{background-image:url(:/playCtrlBar/resources/playctrlBar/pre_hover.svg);border:none;}"
        "QPushButton:pressed{background-image:url(:/playCtrlBar/resources/playctrlBar/pre.svg);border:none;}");

    PlayButton = new QPushButton(this);
    PlayButton->setText("");
    PlayButton->setFixedSize(48, 48);
    PlayButton->setStyleSheet("QPushButton{background-image:url(:/playCtrlBar/resources/playctrlBar/play.svg);border:none;}"
        "QPushButton:hover{background-image:url(:/playCtrlBar/resources/playctrlBar/play_hover.svg);border:none;}"
        "QPushButton:pressed{background-image:url(:/playCtrlBar/resources/playctrlBar/play.svg);border:none;}");

    NextButton = new QPushButton(this);
    NextButton->setText("");
    NextButton->setFixedSize(32, 32);
    NextButton->setStyleSheet("QPushButton{background-image:url(:/playCtrlBar/resources/playctrlBar/next.svg);border:none;}"
        "QPushButton:hover{background-image:url(:/playCtrlBar/resources/playctrlBar/next_hover.svg);border:none;}"
        "QPushButton:pressed{background-image:url(:/playCtrlBar/resources/playctrlBar/next.svg);border:none;}");

    volumeButton = new PlaybackVolumeButton(this);
    volumeButton->setText("");
    volumeButton->setFixedSize(32, 32);

    QHBoxLayout* pHLay = new QHBoxLayout(this);
    pHLay->addWidget(StopButton);
    pHLay->setSpacing(8);
    pHLay->addWidget(PreButton);
    pHLay->setSpacing(8);
    pHLay->addWidget(PlayButton);
    pHLay->setSpacing(8);
    pHLay->addWidget(NextButton);
    pHLay->setSpacing(8);
    pHLay->addWidget(volumeButton);

    pHLay->setContentsMargins(0, 0, 0, 0);

    setLayout(pHLay);

    setFixedSize(32 * 4 + 48 + 4 * 8 + 20 , 48);

    connect(PlayButton, &QPushButton::clicked, this, &PlaybackPlayButtonGroup::sig_play);
    connect(StopButton, &QPushButton::clicked, this, &PlaybackPlayButtonGroup::sig_stop);
    connect(PreButton, &QPushButton::clicked, this, &PlaybackPlayButtonGroup::sig_pre);
    connect(NextButton, &QPushButton::clicked, this, &PlaybackPlayButtonGroup::sig_next);
}

PlaybackPlayButtonGroup::~PlaybackPlayButtonGroup()
{
}

//void PlaybackPlayButtonGroup::setVLC(VLCKits *vlcKits)
//{
//    if(vlcKits){
//        _vlcKits = vlcKits;
//        m_pAudioButton->setVLC(_vlcKits);
//    }
//}

void PlaybackPlayButtonGroup::Play(bool isplay)
{
    if(isplay){
        PlayButton->setStyleSheet("QPushButton{background-image:url(:/playCtrlBar/resources/playctrlBar/pause.svg);border:none;}"
            "QPushButton:hover{background-image:url(:/playCtrlBar/resources/playctrlBar/pause_hover.svg);border:none;}"
            "QPushButton:pressed{background-image:url(:/playCtrlBar/resources/playctrlBar/pause.svg);border:none;}");
    }else{
        PlayButton->setStyleSheet("QPushButton{background-image:url(:/playCtrlBar/resources/playctrlBar/play.svg);border:none;}"
            "QPushButton:hover{background-image:url(:/playCtrlBar/resources/playctrlBar/play_hover.svg);border:none;}"
            "QPushButton:pressed{background-image:url(:/playCtrlBar/resources/playctrlBar/play.svg);border:none;}");
    }
}
